﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using KtcAr.Services.Monitors;
using Moq;
using Ktcar.Cs.Common.Validations;
using System.Net.NetworkInformation;

namespace KtcAr.Services.MonitorsTest
{
    /// <summary>
    /// Summary description for WatcherTest
    /// </summary>
    [TestClass]
    public class ServiceMonitorTest
    {
        public ServiceMonitorTest()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void IsAlive_Test ()
        {
            Assert.IsTrue(new PingMonitor("localhost").IsAlive(), "Expecting that localhost is alive");
            Assert.IsTrue(new PingMonitor("165.165.38.147").IsAlive(), "No Internet connection or google is down by ip is alive");
            Assert.IsFalse(new PingMonitor("165.165.38.156").IsAlive(), "Expecting that fake google by ip is not alive");
            Assert.IsTrue(new PingMonitor("www.google.com.ar").IsAlive(), "No Internet connection or google is down by name is alive");
        }

        [TestMethod]
        public void IsAllAlive_OnlyPingMonitors_Test()
        {
            var monitors = new MonitorList();
            monitors.Add(new PingMonitor("localhost"));
            monitors.Add(new PingMonitor("www.google.com.ar"));
            List<MonitorResult> results = monitors.CheckAll();

            results.ForEach(r => Assert.AreEqual(IPStatus.Success, r.PingStatus));
        }

        [TestMethod]
        public void IsReacheable_Test()
        {
            var response = new SocketConnectMonitor("localhost", 80).IsReacheable();
        }

        [TestMethod]
        public void CheckIt_Test()
        {
            var aMonitor = new PingMonitor("localhost");
            Assert.AreEqual(IPStatus.Success, aMonitor.CheckIt().PingStatus);
        }
    }
}
